<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>会员添加测试</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>会员添加功能测试</h1>
    
    <form id="memberForm">
        <div>
            <label>用户名:</label>
            <input type="text" id="user_no" required>
        </div>
        <div>
            <label>密码:</label>
            <input type="password" id="passwd" required>
        </div>
        <div>
            <label>姓名:</label>
            <input type="text" id="name" required>
        </div>
        <div>
            <label>性别:</label>
            <select id="gender">
                <option value="男">男</option>
                <option value="女">女</option>
                <option value="其他">其他</option>
            </select>
        </div>
        <div>
            <label>邮箱:</label>
            <input type="email" id="email" required>
        </div>
        <div>
            <button type="submit">添加会员</button>
        </div>
    </form>
    
    <div id="result"></div>
    
    <script>
        // 配置axios
        axios.defaults.baseURL = 'http://localhost:8085';
        axios.defaults.timeout = 5000;
        
        document.getElementById('memberForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const memberData = {
                user_no: document.getElementById('user_no').value,
                passwd: document.getElementById('passwd').value,
                name: document.getElementById('name').value,
                gender: document.getElementById('gender').value,
                email: document.getElementById('email').value,
                regis_date: new Date().toISOString().slice(0, 19).replace('T', ' ')
            };
            
            try {
                console.log('发送数据:', memberData);
                const response = await axios.post('/member/add', memberData);
                console.log('响应:', response);
                document.getElementById('result').innerHTML = 
                    '<p style="color: green;">添加成功！返回值: ' + response.data + '</p>';
            } catch (error) {
                console.error('错误:', error);
                let errorMsg = '添加失败: ';
                if (error.response) {
                    errorMsg += '状态码 ' + error.response.status + ', 响应: ' + JSON.stringify(error.response.data);
                } else if (error.request) {
                    errorMsg += '网络错误，无法连接到服务器';
                } else {
                    errorMsg += error.message;
                }
                document.getElementById('result').innerHTML = 
                    '<p style="color: red;">' + errorMsg + '</p>';
            }
        });
    </script>
</body>
</html>